import SparkApi_functionCall

appid = "1c4cbff1"     #填写控制台中获取的 APPID 信息
api_secret = "YjFiYzY5MTdkMGViNzdmODcyZjczNjZk"   #填写控制台中获取的 APISecret 信息
api_key ="ee18441c0b4fd6038b24ad9831c03025"    #填写控制台中获取的 APIKey 信息

domain = "4.0Ultra"    # v4.0版本

Spark_url = "wss://spark-api.xf-yun.com/v4.0/chat"  # v4.0环境的地址

text =[{"role":"system","content":"假设你是公司老板，我是公司员工"},
       {"role":"user","content":"十一假期太短了，我必须得请两天"},
       {"role":"assistant","content":"不许请假，给我干活"}]

def getText(role,content):
    text.clear()
    jsoncon = {}
    jsoncon["role"] = role
    jsoncon["content"] = content
    text.append(jsoncon)
    return text

def getlength(text):
    length = 0
    for content in text:
        temp = content["content"]
        leng = len(temp)
        length += leng
    return length

def checklen(text):
    while (getlength(text) > 8000):
        del text[0]
    return text
    


if __name__ == '__main__':

    # while(1):
    #     Input = input("\n" +"我:")
    #     question = checklen(getText("user",Input))
        question = checklen(getText("user","我不请假了"))
    #     print(question)
        SparkApi_functionCall.answer =""
        print("星火:",end = "")
        SparkApi_functionCall.main(appid,api_key,api_secret,Spark_url,domain,question)
        # getText("assistant",SparkApi_functionCall.answer)
        # print("sid:" + SparkApi2.sid)

